$(function () {
    var comment_table;
    layui.use('table',function () {
        var table = layui.table;
        comment_table = table.render({
            elem: '#comment_table'
            ,height: 625 //容器高度
            ,cols: [[
                {fixed:'left',type:'checkbox'},
                {field: 'id', hide:true},
                {field: 'content',title:'评论内容'},
                {field:'commentTime',title:'评论时间'},
                {field:'commentator',title:'评论人名称'},
                {field:'email',title:'评论人邮箱'},
                {field:'status', templet:'#titleTpl',title:'状态'},
                {field:'replyContent',title:'回复内容'}
            ]] //设置表头
            ,toolbar:true
            ,page:true
            ,url:'/table/list/comments'
        });
    })


    $("#comment_verify_btn").click(function () {
        layui.use('table',function () {
            var table = layui.table;
            var checkStatus = table.checkStatus('comment_table');
            var data = checkStatus.data;
            if(data.length>0){
                $.ajax({
                    type:"post"
                    , url:'/comment/verify'
                    , dataType:"json"
                    , contentType: "application/json;charset=utf-8"
                    , data:JSON.stringify(data)
                    , success:function (r) {
                        if(r.status='success'){
                            layer.msg("审核完成");
                        }else{
                            layer.msg("error");
                        }
                        comment_table = table_reload(comment_table,"comment_table");
                    }
                })
            }else{
                layer.msg("请选中至少一条数据");
            }
        })
    })
    $("#comment_delete_btn").click(function () {
        layui.use('table',function () {
            var table = layui.table;
            var checkStatus = table.checkStatus('comment_table');
            var data = checkStatus.data;
            if(data.length>0){
                $.ajax({
                    type:"post"
                    , url:'/comment/delete'
                    , dataType:"json"
                    , contentType: "application/json;charset=utf-8"
                    , data:JSON.stringify(data)
                    , success:function (r) {
                        if(r.status='success'){
                            layer.msg("删除完成");
                        }else{
                            layer.msg("error");
                        }
                        comment_table = table_reload_del(comment_table,"comment_table");
                    }
                })
            }else{
                layer.msg("请选中至少一条数据");
            }
        })
    })


    $("#refresh").click(function () {
        location.reload();
    })


})